package org.smartboot.flow.core.util;

/**
 * @author qinluo
 * @date 2022-11-20 11:32:23
 * @since 1.0.0
 */
public final class AuxiliaryUtils {

    public static <T> T or(T t, T defaultValue) {
        return t != null ? t : defaultValue;
    }

    public static String or(String t, String defaultValue) {
        return t != null && t.trim().length() > 0 ? t : defaultValue;
    }

    public static boolean isBlank(String value) {
        return value == null || value.trim().length() == 0;
    }

    public static boolean isNotBlank(String value) {
        return !isBlank(value);
    }

    public static boolean isType(String typename) {
        try {
            Class.forName(typename);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public static Class<?> asClass(String typename) {
        try {
            return Class.forName(typename);
        } catch (Exception e) {
            return null;
        }
    }

    public static void appendTab(StringBuilder sb, int numbersOfTab) {
        for (int i = 0; i < numbersOfTab; i++) {
            sb.append("\t");
        }
    }

    public static String contact(String p, Object ...s) {
        StringBuilder sb = new StringBuilder();
        sb.append(p);

        for (Object suffix : s) {
            sb.append("-").append(suffix);
        }

        return sb.toString();
    }
}
